<template>
  <!-- 系统账户管理 -->
  <div>
    <!-- 头部 -->
    <div class="header">
      <!-- 日期选择 -->
      <el-date-picker
        v-model="time"
        type="datetimerange"
        :picker-options="pickerOptions"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        align="right"
      >
      </el-date-picker>
      <!-- 消费选择框 -->
      <el-select
        style="margin-left: 10px"
        v-model="consumption"
        clearable
        placeholder="请选择类型"
      >
        <el-option label="充值" value="充值"></el-option>
        <el-option label="收益" value="收益"></el-option>
        <el-option label="体现" value="体现"></el-option>
      </el-select>
      <!-- 审核选择框 -->
      <el-select
        style="margin-left: 10px"
        v-model="audit"
        clearable
        placeholder="请选择状态"
      >
        <el-option label="正常" value="正常"></el-option>
        <el-option label="未审核" value="未审核"></el-option>
      </el-select>
      <!-- 按钮 -->
      <el-button @click="inquire" style="margin-left: 10px" type="primary"
        >查询</el-button
      >
    </div>
    <br />
    <!-- 内容 -->
    <div>
      <!-- 表格 -->
      <el-table :data="formData" stripe style="width: 100%">
        <el-table-column prop="id" label="编号" width="240" align="center">
        </el-table-column>
        <el-table-column
          prop="transferMoney"
          label="交易金额"
          width="240"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="transferTime"
          label="交易时间"
          width="240"
          align="center"
        >
          <template slot-scope="scope">
            <span> {{ zh(scope.row.transferTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="type"
          label="交易类型"
          width="240"
          align="center"
        >
        </el-table-column>
        <el-table-column label="状态" width="240" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.status == '正常'" style="color: green"
              >正常</span
            >
            <span v-if="scope.row.status == '未审核'" style="color: red"
              >未审核</span
            >
          </template>
        </el-table-column>
        <el-table-column prop="description" label="描述" align="center">
        </el-table-column>
      </el-table>
    </div>
    <!-- 尾部 -->
    <div class="paginetion">
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-sizes="[4, 6, 8, 10]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { get, post } from "@/utils/request";
import moment from "moment";
export default {
  data() {
    return {
      //时间选择框
      time: null,
      //消费选择框
      consumption: "",
      //审核选择框
      audit: "",
      //表格初始化
      formData: [],
      //页数
      page: 1,
      //每页总条数
      pageSize: 8,
      //总页数
      total: 30,
      //查询参数
      inquireData: {},
      //头部时间栏
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              let end = new Date();
              let start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              let end = new Date();
              let start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              let end = new Date();
              let start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  computed: {},
  methods: {
    //获取每页数据
    async getMessage() {
      let data = {
        page: this.page,
        pageSize: this.pageSize,
      };
      let res = await get("/account/pageQuerySystemAccount", {
        ...data,
        ...this.inquireData,
      });
      this.formData = res.data.list;
      this.total = res.data.total;
    },
    //底部分页
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.page = 1;
      this.getMessage();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.page = val;
      this.getMessage();
    },
    //转换时间
    zh(time) {
      return moment(parseInt(time)).format("YYYY/MM/DD hh:mm:ss");
    },
    //查询
    inquire() {
      let data = {
        //类型
        type: this.consumption,
        //状态
        status: this.audit,
      };
      if (!(this.time == null)) {
        //开始时间
        data.beginTime = moment(this.time[0]).valueOf();
        //结束时间
        data.endTime = moment(this.time[1]).valueOf();
      }
      for (let key in data) {
        if (!data[key]) {
          delete data[key];
        }
      }
      this.inquireData = data;
      this.page = 1;
      this.getMessage();
    },
  },
  //生命周期钩子函数
  created() {
    //获取每页的数据
    this.getMessage();
  },
  mounted() {},
};
</script>
<style scoped>
/* .header {
  line-height: 20px;
} */
.paginetion {
  position: fixed;
  bottom: 40px;
  right: 10px;
}
</style>